package com.loveshes.springbootstudy1.common;

import com.fasterxml.jackson.annotation.JsonIgnore;

/**
 * 通用返回实体
 *
 * @Author WangZhe
 * @Date 2021-12-18 21:55
 */
public class JsonData<T> {

    private Integer status; // 状态码 0成功 非0失败
    private String message; // 描述信息
    private T data; // 返回数据

    public JsonData<T> status(Integer status) {
        this.status = status;
        return this;
    }

    public JsonData<T> message(String message) {
        this.message = message;
        return this;
    }

    public JsonData<T> data(T data) {
        this.data = data;
        return this;
    }

    @JsonIgnore
    public boolean isSuccess() {
        return JsonResult.STATUS_SUCCESS.equals(this.status);
    }

    @JsonIgnore
    public boolean isFail() {
        return JsonResult.STATUS_FAIL.equals(this.status);
    }

    public Integer getStatus() {
        return status;
    }

    public void setStatus(Integer status) {
        this.status = status;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }

    @Override
    public String toString() {
        return "JsonData{" +
                "status=" + status +
                ", msg='" + message + '\'' +
                ", data=" + data +
                '}';
    }
}
